package com.xt.base.model.dictionary;


import java.util.Date;

import com.xt.base.dao.hibernate.code.IAutoCreateCode;
import com.xt.base.model.base.SpelledField;
import com.xt.base.pojo.BasePOJO;

/**
 * 数据字典基类 <br>
 * <br>
 * 
 * <p>
 * <a href="Dictionary.java.html"><i>查看源文件</i></a>
 * </p>
 * 
 * @author 杨洪波
 * @version $Revision: $<br>
 *          $Id: $ 
 * @hibernate.class table="Dictionary" batch-size="200" dynamic-update="true" dynamic-insert="true"
 * 
 * @hibernate.discriminator column="Type" type="string" length="40"
 */
public abstract class BaseDictionary extends BasePOJO implements IAutoCreateCode{
	private static final long serialVersionUID = 7604374965530142221L;

	/** 名称(或中文简称) */
	private SpelledField name;
	
	/** 国家编码 */
	private String nationalCode;
	
	/** 是否停用 */
	private boolean closed;
	
	/** 停用时间 */
	private Date closeTime;
	
	/** 上级字典 */
	protected BaseDictionary superior;
	
	/** 是否目录 */
	private boolean catalog;
	
	private int showOrder;
	
	public BaseDictionary(){
		this.closed = false;
		this.catalog = false;
		this.superior = null;
	}
	
	public BaseDictionary(String name){
		this.closed = false;
		this.catalog = true;
		this.superior = null;
		this.name = new SpelledField(name);
	}
	
	public BaseDictionary(String name,String nationalCode){
		this();
		this.name = new SpelledField(name);
		this.nationalCode = nationalCode;
	}

	public String[] getJustProperties() {
		return new String[]{"code","clazz","name","nationalCode","closed","catalog","superior.code","superior.clazz"};
	}

	/**
	 * @hibernate.property column="Closed" not-null="true"
	 * @return 是否停用
	 */
	public boolean isClosed() {
		return closed;
	}

	public void setClosed(boolean closed) {
		this.closed = closed;
	}

	/**
	 * @hibernate.property column="CloseTime"
	 * @return 停用时间
	 */
	public Date getCloseTime() {
		return closeTime;
	}

	public void setCloseTime(Date closeTime) {
		this.closeTime = closeTime;
	}

	/**
	 * @hibernate.component 
	 * @return 名称
	 */
	public SpelledField getName() {
		return name;
	}

	public void setName(SpelledField name) {
		this.name = name;
	}

	/**
	 * @hibernate.property column="NationalCode"
	 * @return 国家编码
	 */
	public String getNationalCode() {
		return nationalCode;
	}

	public void setNationalCode(String nationalCode) {
		this.nationalCode = nationalCode;
	}

	/**
	 * @hibernate.many-to-one column = "Superior_ID" index="idxSuperior_ID"
	 * 		class="com.xt.base.model.dictionary.BaseDictionary"
	 * @return 上级字典
	 */
	public BaseDictionary getSuperior() {
		return (BaseDictionary)superior;
	}

	public void setSuperior(BaseDictionary superior) {
		this.superior = superior;
	}

	/**
	 * @hibernate.property column="Catalog" not-null="true" unique="false"
	 * @return 是否目录
	 */
	public boolean isCatalog() {
		return catalog;
	}

	public void setCatalog(boolean catalog) {
		this.catalog = catalog;
	}
	
	private BaseDictionary dictionaryCatalog;
	private boolean catalogBinded = false;
	
	public BaseDictionary getDictionaryCatalog() {
		if(!catalogBinded){
			dictionaryCatalog = this;
			for(;dictionaryCatalog != null && !dictionaryCatalog.isCatalog();
				dictionaryCatalog = dictionaryCatalog.getSuperior());
			catalogBinded = true;
		}
		return dictionaryCatalog;
	}

	/**
	 * @hibernate.property column="ShowOrder"
	 * @return 显示顺序
	 */
	public int getShowOrder() {
		return showOrder;
	}

	public void setShowOrder(int showOrder) {
		this.showOrder = showOrder;
	}

}
